package com.yugao.fintech.antelope.codegen.controller;

import com.yugao.fintech.antelope.codegen.model.rqrs.CodeFileRS;
import com.yugao.fintech.antelope.codegen.model.rqrs.GeneratorRQ;
import com.yugao.fintech.antelope.codegen.service.GeneratorService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "生成代码")
@RestController
@RequestMapping("/genCode")
@RequiredArgsConstructor
public class GeneratorController {
    private final GeneratorService generatorService;

    /**
     * 生成代码
     *
     * @param generatorRQ 生成参数
     * @return 返回代码内容
     */
    @RamResource(action = "lcp:genCode:gen", name = "低代码-生成代码", type = ActionType.READ)
    @PostMapping
    public Resp<List<CodeFileRS>> genCode(@RequestBody @Validated GeneratorRQ generatorRQ) {
        return Resp.ok(generatorService.generate(generatorRQ));
    }
}
